<template>
  <view>
    <view class="store_info">
      <view class="main">
        <view class="avatar">
          <image :src="store.user.avatarUrl" mode="aspectFill"></image>
        </view>
        <view class="info"> 
          <view class="fs30 fw">{{store.store_clerk.real_name}}</view>
          <view class="mt10">门店名称：{{store.store_name}}</view>
          <view class="mt10">所属店铺：{{store.supplier_shop.name}}</view>
        </view>
        <view class="money" @click="go_income">
          <image src="@/static/icon/pay_icon.png" mode="aspectFill"></image>
          <view class="">收益</view>
        </view>
      </view>
    </view>
    <view class="fff_box">
      <view class="title_box">
        <view class="title">
          核销记录
        </view>
        <view class="search-box">
          <text class="icon iconfont icon-sousuo"></text>
          <input v-model="search" type="text" placeholder="请输入核销人姓名" @confirm="onconfirm" />
          <view class="search">搜索</view>
        </view>
      </view>
      <view class="top-tabbar">
      	<view :class="state_active == 'all' ? 'tab-item active' : 'tab-item'" @click="stateFunc('all')">全部订单</view>
      	<view :class="state_active == 'payment' ? 'tab-item active' : 'tab-item'" @click="stateFunc('payment')">待付款</view>
      	<view :class="state_active == 'delivery' ? 'tab-item active' : 'tab-item'" @click="stateFunc('delivery')">待发货</view>
      	<view :class="state_active == 'received' ? 'tab-item active' : 'tab-item'" @click="stateFunc('received')">待收货</view>
      	<view :class="state_active == 'comment' ? 'tab-item active' : 'tab-item'" @click="stateFunc('comment')">待评价</view>
      </view>
      <view v-if="list.length==0" style="text-align: center;margin-top: 40rpx;">暂无核销记录</view>
      <!-- <view class="item" v-for="(item,index) in list" :key="index">
				<view class="">
					<view class="c-333 fs28 lh50">订单编号：{{item.order.order_no}}</view>
					<view class="c-555 fs28 lh50">核销人：{{item.clerk.real_name}}</v0.00iew>
					<view class="c-999 fs24 lh50">{{item.create_time}}</view>
				</view>
				<view class="fs28" style="font-weight: bold;color: #1BAE61;">
					+{{item.order.hx_money}}
				</view>
			</view> -->
      <view class="order-item" v-for="(item,index) in list" :key="item.order.order_no">
        <view class="item-title">
          <text>下单日期:{{item.create_time}}</text>
          <text>{{item.order.order_status.text}}</text>
        </view>
        <view class="item-goods" v-for="(el,indexs) in item.product" :key="indexs">
          <image :src="el.image.file_path" mode=""></image>
          <view>
            <view>{{el.product_name}}</view>
            <view>商品数量：{{el.total_num}}</view>
            <view>商品金额：￥{{el.total_price}}</view>
          </view>
        </view>
        <view class="item-price">
          <text>预估佣金：</text>
          <text>￥{{item.order.hx_money}}</text>
        </view>
        <view class="item-action">
          <text>订单号：{{item.order.order_no}}</text>
          <view class="action-btn" @click="handlePhone(item.mobile)">
            <image src="/static/icon_phone.png" mode=""></image>
            <text>{{item.nickName}}</text>
          </view>
        </view>
      </view>
    </view>
    <!-- 暂未绑定门店 -->
    <view class="popup_no_store" v-if="show_popup" @click.stop="">
      <view class="main">
        <image src="@/static/no_mendian.png" mode="widthFix"></image>
        <button class="btn" @click="goback">我知道啦</button>
      </view>
    </view>
  </view>
</template>

<script>
  export default {
    data() {
      return {
        show_popup: false,
        store: {},
        search: '',
        page: 1,
        list_rows: 15,
        list: [],
        last_page: 0,
        state_active:'all'
      }
    },
    onLoad() {
      this.is_store()
    },
    onShow() {
      this.page = 1
      this.list = []
      this.getList()
    },
    onReachBottom() {
      if (this.last_page > this.page) {
        this.page++
        this.getList()
      }
    },
    methods: {
      
      handlePhone(phone){
        uni.makePhoneCall({
          phoneNumber:phone
        })
      },
      stateFunc(e){
        this.state_active = e
        this.page = 1
        this.getList()
      },
      onconfirm() {
        this.page = 1
        this.list = []
        this.getList()
      },
      goback() {
        uni.navigateBack()
      },
      getList() {
        let self = this;
        let params = {}
        params.page = self.page
        params.search = self.search
        params.list_rows = self.list_rows
        params.dataType = self.state_active
        self._get('store.order/orderList', params, function(res) {
          if(self.page == 1){
            self.list =  res.data.data
          }else{
            self.list = self.list.concat(res.data.data)
          }
          self.last_page = res.data.last_page
        });
      },
      is_store() {
        let self = this;
        self._get('store.order/is_store', {}, function(res) {
          if (res.data == 0) {
            self.show_popup = true
          } else {
            self.getData()
          }
        });
      },
      getData() {
        let self = this;
        self._get('store.order/store', {}, function(res) {
          self.store = res.data
        });
      },
      go_income() {
        uni.navigateTo({
          url: '/pages/mystore/income'
        })
      }
    }
  }
</script>

<style lang="scss" scoped>
  .popup_no_store {
    position: fixed;
    left: 0;
    right: 0;
    top: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.4);
    display: flex;
    align-items: center;
    justify-content: center;

    .main {
      margin-top: -320rpx;

      .btn {
        width: 500rpx;
        height: 88rpx;
        margin: 0 auto;
        line-height: 88rpx;
        border-radius: 16rpx;
        background-color: #1BAE61;
        color: #fff;
        margin-top: -140rpx;
        font-size: 30rpx;
      }

      image {
        width: 620rpx;
      }
    }

  }

  .fs24 {
    font-size: 24rpx;
  }

  .fs28 {
    font-size: 28rpx;
  }

  .lh50 {
    line-height: 50rpx;
  }

  .c-333 {
    color: #333333;
  }

  .c-555 {
    color: #555555;
  }

  .c-999 {
    color: #999999;
  }

  .fff_box {
    width: 700rpx;
    margin: 0 auto;
    padding: 20rpx;
    box-sizing: border-box;
    border-radius: 16rpx;
    background-color: #fff;
    margin-top: -200rpx;

    .item {
      width: 100%;
      margin: 20rpx auto;
      padding: 20rpx;
      box-sizing: border-box;
      border-radius: 16rpx;
      border: 1rpx solid #eaeaea;
      display: flex;
      align-items: center;
      justify-content: space-between;
    }

    .title_box {
      padding-bottom: 20rpx;
      line-height: 50rpx;
      height: 50rpx;
      border-bottom: 1rpx solid #eaeaea;
      display: flex;
      align-items: center;
      justify-content: space-between;

      .title {
        font-size: 30rpx;
        color: #333333;
        font-weight: bold;
      }

      .search-box {
        height: 50rpx;
        display: flex;
        align-items: center;
        border: 1rpx solid #eaeaea;
        padding: 10rpx;
        border-radius: 8rpx;
        box-sizing: border-box;

        input {
          height: 30rpx;
          flex: 1;
          padding: 10rpx;
          font-size: 22rpx;
        }

        .search {
          color: #999999;
          padding-left: 10rpx;
        }
      }
    }
  }

  .fs30 {
    font-size: 30rpx;
  }

  .fw {
    font-weight: bold;
  }

  .store_info {
    width: 100%;
    height: 400rpx;
    background: linear-gradient(#1BAE61 75%, #F6F6F6);

    .main {
      display: flex;
      align-items: center;
      width: 700rpx;
      margin: 0 auto;
      padding-top: 40rpx;

      .avatar {
        width: 100rpx;
        height: 100rpx;

        image {
          width: 100rpx;
          height: 100rpx;
          border-radius: 50%;
        }
      }

      .info {
        flex: 1;
        padding-left: 20rpx;
        color: #fff;
        font-size: 22rpx;
      }

      .money {
        color: #fff;
        text-align: center;
        font-size: 24rpx;

        image {
          width: 48rpx;
          height: 48rpx;
        }
      }
    }
  }

  .order-item {
    border-radius: 12rpx;

    .item-title {
      padding: 30rpx;
      border-bottom: 1px solid #fafafa;
      color: #333;
      font-size: 24rpx;
      display: flex;
      align-items: center;
      justify-content: space-between;

      text+text {
        color: #F22B2F;
      }
    }

    .item-goods {
      color: #333;
      font-size: 28rpx;
      border-bottom: 1px solid #fafafa;
      display: flex;
      align-items: center;
      padding: 30rpx;

      view+view {
        font-size: 24rpx;
        color: #999;
        margin-top: 12rpx;
      }

      image {
        width: 128rpx;
        height: 128rpx;
        margin-right: 20rpx;
      }
    }

    .item-price {
      padding: 30rpx;
      border-bottom: 1px solid #fafafa;
      color: #333;
      font-size: 24rpx;
      display: flex;
      align-items: center;
      justify-content: space-between;

      text+text {
        color: #F22B2F;
      }
    }

    .item-action {
      padding: 20rpx 30rpx;
      border-bottom: 1px solid #fafafa;
      color: #333;
      font-size: 24rpx;
      display: flex;
      align-items: center;
      justify-content: space-between;

      .action-btn {
        padding: 10rpx 20rpx;
        border-radius: 60rpx;
        color: #F22B2F;
        font-size: 28rpx;
        border: 1px solid #F22B2F;
        display: flex;
        align-items: center;
        
        image {
          width: 40rpx;
          height: 40rpx;
          margin-right: 5rpx;
        }
      }
    }
  }
  .tab-item {
  	font-size: 28rpx;
  }
  
  .tab-item.active {
  	font-weight: normal;
  	font-size: 28rpx;
    color: #04be01;
  }
  
  .tab-item.active::after {
  	width: 57rpx;
  	height: 6rpx;
  	background-color: #ff5649;
  }
</style>